﻿<?php
define("ordown",plugin_dir_path(__FILE__));

function refresh_url($ordown_content) {
	if(is_singular()){
		global $wpdb;
		global $post;
		$id = get_the_ID();
		$query = "SELECT `link_id`,`view_id` FROM `vw_xxurls_links` where `post_id` = '{$id}'";
		$view_id = $wpdb->get_results($query);
		if($view_id !== null && count($view_id) == 1){
			echo'<script type="text/javascript">var view_id = "'.$view_id[0]->view_id.'",link_id = "'.$view_id[0]->link_id.'";</script>';
		}else{
		//echo'<script type="text/javascript">console.log("'.$id.'")</script>';
		}
	}
	return $ordown_content;
}

function do_refresh(){
    echo'<script type="text/javascript">if(typeof view_id !== "undefined") {view_action(view_id,link_id);}</script>';
}

add_action('the_content','refresh_url');
add_action('wp_footer', 'do_refresh', 100 );
?>